package com.example.demo0


interface Computer{
    val cpu:String
}

class PC(override val cpu:String="Core"):Computer
class Server(override val cpu:String="Xeon"):Computer

enum class ComputerType{
    PC,Server
}

class ComputerFactory1{
    fun produce(type: ComputerType):Computer{
        return when(type){
            ComputerType.PC -> PC()
            ComputerType.Server -> Server()
        }
    }
}

object ComputerFactory{
    fun produce(type: ComputerType):Computer{
        return when(type){
            ComputerType.PC->PC()
            ComputerType.Server->Server()
        }
    }

    operator fun invoke(type: ComputerType):Computer{
        return when(type){
            ComputerType.PC->PC()
            ComputerType.Server->Server()
        }
    }


}


interface Computer2{
    val cpu:String
    companion object{
        operator fun invoke(type: ComputerType):Computer{
            return when(type){
                ComputerType.PC->PC()
                ComputerType.Server->Server()
            }
        }
    }
}

interface Computer3{
    val cpu:String
    companion object Factory{
        operator fun invoke(type: ComputerType):Computer{
            return when(type){
                ComputerType.PC->PC()
                ComputerType.Server->Server()
            }
        }
    }
}

/**
fun Computer.Companion.fromCPU(cpu:String):ComputerType?=when(cpu){
    "Core"->ComputerType.PC
    "Xeon"->ComputerType.Server
    else->null
}
*/












